/**
 * User: alesj
 * Date: 2005.6.10
 * Time: 13:04:34
 * 
 * (C) Genera Lynx d.o.o.
 */

package com.generalynx.ecos.utils;

import javax.servlet.http.HttpServletRequest;

public class HttpContext implements Context {

    private boolean useSession;
    private HttpServletRequest request;

    public HttpContext(HttpServletRequest request) {
        this.request = request;
    }

    public HttpContext(HttpServletRequest request, boolean useSession) {
        this(request);
        this.useSession = useSession;
    }

    public HttpServletRequest getRequest() {
        return request;
    }

    public Object getAttribute(String key) {
        Object value = request.getAttribute(key);
        if (value == null) {
            return request.getSession(false).getAttribute(key);
        }
        return null;
    }

    public void setAttribute(String key, Object value) {
        if (useSession) {
            request.getSession(false).setAttribute(key, value);
        } else {
            request.setAttribute(key, value);
        }
    }

}
